package org.ccay.security.exception;

/**
 * 用户凭据错误异常
 * @author chaowangbang
 *
 */
public class IncorrectCredentialsException extends org.apache.shiro.authc.IncorrectCredentialsException implements IFriendlyException{

	private static final long serialVersionUID = 20171117L;
	
	private static final String ERROR_CODE = "ccay.security.login.incorrectCredentials";
	
	/**
	 * 重试限制（剩余可重试次数） -1表示不限制
	 */
	private int retryLimit = -1;
	
	/**
	 * 重试此时用完后将被锁定时间
	 */
	private int willBeLockSecond = 0;


	public IncorrectCredentialsException(String message) {
		super(message);
	}
	
	public IncorrectCredentialsException(String message,int retryLimit, int willBeLockSecond) {
		super(message);
		this.retryLimit = retryLimit;
		this.willBeLockSecond = willBeLockSecond;
	}
	
//	@Override
//	public String getMessage(){
//		String msg = SecurityI18nUtil.getI18nMessage("ccay.security.login.incorrectCredentials", "zh_CN");
//		if(retryLimit>0){
//			msg += SecurityI18nUtil.getI18nMessage("ccay.security.login.attempts", "zh_CN");
//		}
//		return MessageFormat.format(msg,retryLimit,willBeLockSecond);
//	}

	public int getRetryLimit() {
		return retryLimit;
	}

	public int getWillBeLockSecond() {
		return willBeLockSecond;
	}

	@Override
	public String getErrCode() {
		return ERROR_CODE;
	}

	@Override
	public Object[] getArgs() {
		if(retryLimit>0){
			return new Object[]{retryLimit,willBeLockSecond};
		}
		return new Object[]{};
	}

	@Override
	public String getI18nKey() {
		if(retryLimit>0){
			return "ccay.security.login.incorrectCredentialsWithAttemptInfo";
		}
		return ERROR_CODE;
	}

}
